package org.example.shop_front_api.controller;

import org.example.shop_front_api.entity.User;
import org.example.shop_front_api.service.UserService;
import org.example.shop_front_api.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/user")
public class UserController {
    @Autowired
    private UserService userService;

    // 一对多关联查询：根据ID查询用户及地址列表
    @GetMapping("/with-addresses/{userId}")
    public JsonResult getUserWithAddresses(@PathVariable Long userId) {
        User user = userService.getUserWithAddresses(userId);
        if (user == null) {
            return JsonResult.failed(404, "用户不存在");
        }
        return JsonResult.success("查询成功", user);
    }
}
